Skip to content

feat(auth): add OpenID Connect sign-in - #9

Open
ParadoxPixel wants to merge 3 commits into
pixelib:mainfrom
ParadoxPixel:feature/oidc
Open

ParadoxPixel wants to merge 3 commits into
pixelib:mainfrom
ParadoxPixel:feature/oidc

Conversation

@ParadoxPixel

@ParadoxPixel ParadoxPixel commented Nov 17, 2026 •

Copy link
Copy Markdown

Adds single sign-on through any OpenID Connect provider. I wanted to run Arca behind my own
identity provider without keeping a separate password account around, so the setup wizard can
take its administrator from the provider too.

It is off by default. An instance that does not set OIDC_ISSUER behaves exactly as before.

Sign-in is the authorization code flow with PKCE, state and nonce, and it ends in the same session
cookie as a password login, so nothing behind the login changes. Accounts are matched on the
provider's issuer and subject, kept in a new user_identities table. Arca never matches on email
alone, because that would let anyone who can set an email at the provider into the matching
account. A user whose email changes at the provider keeps their account. Accounts created this way
have no password, and password login refuses them.

With OIDC_ADMIN_GROUPS set, the role of a linked account follows group membership on every
sign-in, and the last enabled administrator is never demoted. The user list then locks the role of
those accounts, since a change made in Arca would be undone at the next sign-in. Without admin
groups Arca leaves roles alone. The display name comes from the provider only when the account is
created, so a name edited in Arca stays. OIDC_ALLOWED_GROUPS turns away anyone outside those
groups, and a sign-in whose email already belongs to an account is refused unless
OIDC_LINK_EXISTING is on.

Before setup, a provider sign-in creates nothing. It only fills in the wizard's administrator step,
and the setup token is still required. With admin groups set, only a member of one can do this,
since the role sync would otherwise demote the setup administrator at their next sign-in.

Maven, npm and Docker clients keep using API tokens. Configuration is env vars and flags, and
docs/oidc.md has the table and an Authentik example.

Setup wizard After signing in at the provider
image image
Setup refused for a non-admin Login page Refused sign-in
image image image
User list with SSO accounts
image

I left a few things out on purpose. Mapping groups to per-repository grants needs a schema change
and did not belong in a first version. OIDC is not configurable from the admin UI, and GitHub login
without an OIDC provider in between is not supported. Removing someone at the provider takes effect
at their next sign-in only, while their sessions and API tokens outlive it. docs/oidc.md says so.

Two new dependencies come in, coreos/go-oidc/v3 and golang.org/x/oauth2. The second requires
go 1.26.0 in go.mod. go mod tidy also moved the existing direct dependencies out of the
// indirect block, which is why that diff looks bigger than it is. I exported auth.isSecure so
the OIDC cookies follow the same Secure rule as the session cookie. Identities waiting for setup
live in server memory, so nothing reaches the database before the setup transaction and a restart
only means signing in again. While the browser is away at the provider, the wizard keeps its fields,
setup token included, in sessionStorage. I accepted that over moving the button to the first step,
because the token is useless once setup completes and the wizard's flow stays as it was.

Password login now runs the decoy hash for accounts without a password too, so the response time
does not tell an SSO account apart from an unknown email.

go vet, go test ./... and pnpm typecheck pass. The OIDC tests run against a fake provider that
signs real ID tokens. On the final commit I ran a scripted browser pass against Keycloak 26 with the
image built from the Dockerfile. It covered the refusal of a non-admin at setup, setup through the
provider as an admin, sign-in after setup with roles from groups, the locked role in the user list,
and refusal outside the allowed groups. The build has also been running in my own production
instance against Authentik. I have not tried a provider that leaves the groups claim out of the ID
token.

To implement this feature I made use of Claude Fable 5.2.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Lets Arca run behind an identity provider without separate password
accounts. Off unless OIDC_ISSUER is set.

- code flow with PKCE, state and nonce, ending in the normal session
- accounts linked by issuer and subject, never by email alone
- OIDC_ADMIN_GROUPS syncs the role each sign-in; last admin kept
- OIDC_ALLOWED_GROUPS gates sign-in; OIDC_LINK_EXISTING opts in to
  linking an existing account by email
- passwordless accounts get the decoy hash at password login so
  timing does not reveal them
An instance behind a provider should need no password account at all.
Before setup a provider sign-in creates nothing: verified claims wait
in memory under a cookie until the wizard makes them the admin, with
the setup token still required and the shown email echoed back so a
second tab cannot swap the identity. With admin groups set only a
member may do this, so later role sync never demotes the setup admin.
With admin groups set, a role edited in Arca was silently undone at
the user's next sign-in. Linked accounts now refuse role edits, and
the users table marks SSO accounts with a key badge and explains the
locked role in a tooltip. Also widens the role select, which cut off
"Administrator".

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant